package com.insyte.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.insyte.R;

/**
 * DialogUtility
 *
 * @author thangpv
 */
public final class DialogUtils {
    /**
     * Show an alert dialog box
     *
     * @param context
     * @param message
     */

    public static void showAlert(Context context, String message) {
        // if (context != null) {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
        alertDialog.setIcon(R.drawable.ic_logo);
        alertDialog.setTitle(context.getString(R.string.app_name));
        alertDialog.setMessage(message);
        alertDialog.setPositiveButton(R.string.btn_ok,
                new OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                    }
                });
        alertDialog.show();
    }

    // }

    /**
     * Show an alert dialog box
     *
     * @param context
     * @param messageId
     */
    public static void showAlert(Context context, int messageId) {
        // if (context != null) {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
        alertDialog.setTitle(context.getString(R.string.app_name));
        alertDialog.setIcon(R.drawable.ic_logo);
        alertDialog.setMessage(context.getString(messageId));
        alertDialog.setPositiveButton(R.string.btn_ok,
                new OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                    }
                });
        alertDialog.show();
        // }
    }

    public static void showOkDialog(Context context, int messageId,
                                    int OkTextId, final OnClickListener onOKClick) {
        if (context != null) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
            alertDialog.setTitle(context.getString(R.string.app_name));
            alertDialog.setIcon(R.drawable.ic_logo);
            alertDialog.setMessage(context.getString(messageId));

            alertDialog.setPositiveButton(OkTextId, onOKClick);
            alertDialog.show();
        }
    }

    public static void showYesNoDialog(final Context context, int messageId,
                                       int OkTextId, int cancelTextId,
                                       final OnClickListener onOKClick) {
        if (context != null) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
            alertDialog.setTitle(context.getString(R.string.app_name));
            alertDialog.setIcon(R.drawable.ic_logo);
            alertDialog.setMessage(context.getString(messageId));
            alertDialog.setNegativeButton(cancelTextId,
                    new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();

                        }
                    });
            alertDialog.setPositiveButton(OkTextId, onOKClick);
            alertDialog.show();
        }
    }

    public static void showYesNoDialog(final Context context, String title, int messageId,
                                       int OkTextId, int cancelTextId,
                                       final OnClickListener onOKClick) {
        if (context != null) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
            alertDialog.setTitle(title);
            alertDialog.setIcon(R.drawable.ic_logo);
            alertDialog.setMessage(context.getString(messageId));
            alertDialog.setNegativeButton(cancelTextId,
                    new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();

                        }
                    });
            alertDialog.setPositiveButton(OkTextId, onOKClick);
            alertDialog.show();
        }
    }

    public static void showYesNoDialog(final Context context, int messageId,
                                       int OkTextId, int cancelTextId,
                                       final OnClickListener onOKClick,
                                       final OnClickListener onCancelClick) {
        if (context != null) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
            alertDialog.setTitle(context.getString(R.string.app_name));
            alertDialog.setIcon(R.drawable.ic_logo);
            alertDialog.setMessage(context.getString(messageId));
            alertDialog.setNegativeButton(cancelTextId, onCancelClick);
            alertDialog.setPositiveButton(OkTextId, onOKClick);
            alertDialog.show();
        }
    }

    public static void showSimpleOptionDialog(Activity mContext, int titleId,
                                              String[] items, String positiverButton,
                                              OnClickListener itemOnClick,
                                              OnClickListener positiveOnClick) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(mContext.getString(titleId));
        builder.setItems(items, itemOnClick);
        builder.setPositiveButton(positiverButton, positiveOnClick);
        AlertDialog alert = builder.create();
        alert.show();
    }

    public static void showSimpleOptionDialog2(Context mContext, int titleId,
                                               String[] items, String positiverButton, int selectIndex,
                                               OnClickListener positiveOnClick) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(mContext.getString(titleId));
        builder.setSingleChoiceItems(items, selectIndex, null);
        builder.setPositiveButton(positiverButton, positiveOnClick);
        builder.setNegativeButton(mContext.getText(R.string.btn_cancel),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

    public static void Alert(Context context, String message,
                             OnClickListener onOkClick) {
        if (context != null) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
            alertDialog.setTitle(R.string.app_name);
            alertDialog.setIcon(R.drawable.ic_logo);
            alertDialog.setMessage(message);
            alertDialog.setPositiveButton(R.string.btn_ok, onOkClick);
            alertDialog.show();
        }
    }

}
